#ifndef TEXTURE_H
#define TEXTURE_H

#include <string_view>
#include <exception>
#include <QImage>

class Texture
{
private:
    QImage img;
public:
    [[nodiscard]] QColor GetPixel(float u, float v) const
    {
        int ix = (int)std::round((float)img.width() * u) % img.width();
        int iy = (int)std::round((float)img.height() * v) % img.height();
        if (ix < 0) ix += img.width();
        if (iy < 0) iy += img.height();
        return img.pixelColor(ix, iy);
    }
    explicit Texture(const std::string_view& path) : img(path.data()) { }
};

#endif //TEXTURE_H
